#ifndef __M_LOGGER_H__
#define __M_LOGGER_H__
#include <iostream>
#include <ctime>
#include <string>
#include <cstring>



enum class logLevel : unsigned int 
{
    DEBUG = 0,
    INFO = 1,
    WARNING = 2,
    ERROR = 3,
    TEST = 4
};

//随时调整日志过滤等级, 进而调整日志打印信息
#define filter logLevel::DEBUG

class Log
{
public:
    static std::string makeLogLevel(logLevel level)
    {
        std::string str;
        switch(level)
        {
            case logLevel::DEBUG: str += "\033[0m[调试日志]"; break; //默认
            case logLevel::INFO: str += "\033[34m[关键日志]"; break; //绿色
            case logLevel::WARNING: str += "\033[33m[警告日志]"; break; //黄色
            case logLevel::ERROR: str += "\033[31m[错误日志]"; break; //红色
            case logLevel::TEST: str += "\033[96m[临时日志]]"; break;//高亮青色
        }

        if(level >= filter) return str;
    }

    static std::string time()
    {
        std::string str(128,'\0');
        time_t t = ::time(nullptr);
        struct tm* ptm = localtime(&t);
        strftime(&str[0], 128, "%Y-%m-%d %H:%M:%S", ptm);
        str.resize(strlen(str.c_str()));
        return str;
    }
};

#define LOG(level) std::cout << Log::makeLogLevel(level) << "[" << Log::time() << "]" << "[" <<  __FILE__ <<":" << std::to_string( __LINE__) << "]" <<  "[" <<  __func__ << "]" << "\033[0m"

#endif